// components/Header/index.js
const app = getApp()
Component({

 /**
   * 组件的属性列表
   */
  properties: {
    // 导航栏标题
    title: {
      type: String,
      value: "标题"
    },
    // 导航栏背景图
    backgroundImage: {
      type: String,
      value: ""
    },
    // 图片高度
    bgImageHeight: {
      type: String,
      value: ""
    },
    isShowLocaltion: {
      type: Boolean,
      value: false
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    navBarHeight: 0,
    isFixedBg: false,     // 是否显示背景图
    isShowBack: false,    // 是否显示返回按钮
    region: ['广东省', '广州市'],
    customItem: '全部'
  },
  ready(){
    this.setData({
      isFixedBg: this.data.backgroundImage
    })
    this.initialStatusHeight();
    this.initialBackStatus();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 初始化状态栏高度
    initialStatusHeight(){
      const sysInfo = wx.getSystemInfoSync();
      this.setData({
        navBarHeight: sysInfo.statusBarHeight
      });
    },
    bindRegionChange: function (e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
        region: e.detail.value
      })
      app.globalData.region = e.detail.value
    },
    // 初始化返回按钮状态
    initialBackStatus(){
      const pages = getCurrentPages();
      this.setData({
        isShowBack: pages.length>=2
      })
    },
    // 返回事件
    backEvent(){
      wx.navigateBack();
    },
    handleGetLocaltion(){
      wx.getSetting({
        success(res) {
          console.log(res.authSetting['scope.userLocation'])
          if (!res.authSetting['scope.userLocation']) {
            wx.authorize({
              scope: 'scope.userLocation',
              success() {
                wx.getLocation({
                  type: 'wgs84', 
                  success(res) {
                    console.log(res)
                  }
                })
              }
            })
          }else{
            wx.getLocation({
              type: 'wgs84', 
              success(res) {
                console.log(res)
                callback(res.latitude, res.longitude)
              }
            })
          }
        }
      })
    }
  },

})